<template>
	<view class="public-list-follow">
		<template v-if="$_loginOrNot()">
			<view class="split-title" style="border-top: 0;margin-top: 0;">
				<view></view><text>我关注的人</text>
			</view>
			<template v-if="listFollowState == 'success'">
				<view class="list-follow">
					<view
						@click="$_To('user/user?uid=' + item.uid)"
						class="for"
						v-for="item in listFollow"
						:key="item.uid">
						<view class="avatar">
							<view class="image">
								<image :src="item.avatar" mode="widthFix"></image>
							</view>
							<view class="roleName" :style="'background:'+item.nicknameColor+';'">
								<text>{{item.roleName}}</text>
							</view>
						</view>
						<view class="nickname">
							<text>{{item.nickname}}</text>
						</view>
					</view>
					<view
						@click="$_To('publicPage/followUsers')"
						class="for">
						<view class="avatar">
							<view class="image">
								<text class="iconfont icon-wodeguanzhu"></text>
							</view>
						</view>
						<view class="nickname">
							<text>全部</text>
						</view>
					</view>
				</view>
			</template>
			<template v-if="listFollowState == 'loading'">
				<public-loading></public-loading>
			</template>
			<template v-if="listFollowState == 'empty'">
				<public-empty></public-empty>
			</template>
			<view class="split-title" @click="$_To('publicPage/followGroups')">
				<view style="background: #dd524d;"></view>
				<text>我关注的组</text>
				<text style="display: inline-block;margin-left: auto;font-size: 22rpx;color: #C0C4CC;">更多</text>
			</view>
			<template v-if="listFollowGroupState == 'success'">
				<view class="list-follow-group">
					<view
						@click="$_To('group/group?gid='+item.gid)"
						v-for="item in listFollowGroup"
						class="for">
						<view class="cover" v-if="item.cover">
							<image :src="item.cover" mode="widthFix"></image>
						</view>
						<view class="gname">{{item.gname}}</view>
						<view class="follow-button">{{item.interaction.followStatus?'已关注':'未关注'}}</view>
					</view>
				</view>
			</template>
			<template v-if="listFollowGroupState == 'loading'">
				<public-loading></public-loading>
			</template>
			<template v-if="listFollowGroupState == 'empty'">
				<public-empty></public-empty>
			</template>
			<view class="split-title">
				<view style="background: #67C23A;"></view>
				<text>我收藏的帖子</text>
			</view>
			<template v-if="listFollowPostState == 'success'">
				<view class="list-interact">
					<view
						@click="$_To('post/post?pid='+item.pid)"
						class="for Flex"
						v-for="item in listFollowPost"
						:key="item.pid">
						<view
							class="left"
							@click.stop="$_To('user/user?uid=' + item.author.uid)">
							<image :src="item.author.avatar" mode="widthFix"></image>
						</view>
						<view class="right">
							<view class="nickname Zt-ShenLanSe">{{item.author.nickname?item.author.nickname:'?'}}
								<text class="P" :style="item.author.nicknameColor?'color:'+item.author.nicknameColor+';':''">{{item.author.roleName}}</text>
							</view>
							<!-- 文字摘要 -->
							<view class="title" v-if="item.title">{{item.title}}</view>
							<view class="content">{{$_filterHtml(item.content)}}</view>
							<!-- 图片 -->
							<view class="image Flex" v-if="item.files.images.length">
								<view
									@click.stop="$_picturePreview(index,item.files.images)"
									v-for="(images,index) in item.files.images">
									<image :src="images.imageRatioUrl" mode="widthFix"></image>
								</view>
							</view>
							<!-- 视频列表 -->
							<view class="video" v-if="!item.files.images.length && item.files.videos.length">
								<view class="image-cover">
									<image :src="item.files.videos[0].videoPosterUrl" mode="widthFix"></image>
								</view>
								<text class="Flex iconfont icon-play"></text>
							</view>
							<view class="group" v-if="item.group || item.hashtags">
								<view class="_group" v-if="item.group">
									<view><image :src="item.group.cover" mode="widthFix"></image></view>
									<text>{{item.group.gname}}</text>
								</view>
								<view class="_hashtag" v-if="item.hashtags.length">#{{item.hashtags[0].hname}}#</view>
							</view>
							<view
								class="post-info Flex"
								:style="!item.previewLikeUsers && !item.previewComments?'margin-bottom: 0;':''">
								<view class="_position" v-if="item.location && item.location.poi">
									<text class="iconfont icon-dingwei1"></text>
									<text class="_position_POI">{{item.location.poi}}</text>
								</view>
								<text class="P">{{item.createdTimeAgo}}</text>
								<view class="type Flex">
									<text class="Bj-LanSe iconfont icon-tupian" v-if="item.files.images.length"></text>
									<text class="Bj-HongSe iconfont icon-zhibo" v-if="item.files.videos.length"></text>
									<text class="Bj-LvSe iconfont icon-yuyin" v-if="item.files.audios.length"></text>
									<text class="Bj-BianKuangSe iconfont icon-gengduo"></text>
								</view>
							</view>
							<view class="like Bj-BeiJingSe" v-if="item.previewLikeUsers.length">
								<text class="iconfont icon-dianzan"></text>
								<template v-for="item_DianZan in item.previewLikeUsers">
									<text class="H3">{{item_DianZan.nickname}},</text>
								</template>
							</view>
							<view class="comment Bj-BeiJingSe" v-if="item.previewComments.length">
								<template v-for="item_PingLun in item.previewComments">
									<view class="_for">
										<text class="_nickname Zt-ShenLanSe">{{item_PingLun.author.nickname}}:</text>
										<text class="iconfont icon-yuyin" v-if="item_PingLun.files.audios.length"></text>
										<text>{{$_filterHtml(item_PingLun.content)}}</text>
									</view>
								</template>
							</view>
						</view>
					</view>
					<view
						@click="getPostList('more')"
						class="more">点击加载更多</view>
				</view>
			</template>
			<template v-if="listFollowPostState == 'loading'">
				<public-loading></public-loading>
			</template>
			<template v-if="listFollowPostState == 'empty'">
				<public-empty></public-empty>
			</template>
		</template>
		<template v-else>
			<public-not-logged-in></public-not-logged-in>
		</template>
	</view>
</template>

<script>
	export default {
		name:"public-list-follow",
		data() {
			return {
				listFollow:[],
				listFollowState:"loading",
				listFollowGroup:[],
				listFollowGroupState:"loading",
				listFollowPost:[],
				listFollowPostPage:2,
				listFollowPostState:"loading",
			};
		},
		mounted(){
			if(this.$_loginOrNot()){
				this.getFollow();
			}
		},
		methods:{
			// 获取我关注的
			getFollow(){
				this.$_Request(
					"GET","/api/v2/user/"+uni.getStorageSync('user').data.detail.uid+"/mark/follow/users",
					{
						"whitelistKeys":"username,avatar,nicknameColor,roleName,nickname,uid",
						"pageSize":4
					},
					(res) => {
						if(res.data.data.list.length){
							this.listFollow = res.data.data.list;
							this.listFollowState = "success"
						}else{
							this.listFollowState = "empty"
						}
						this.getFollowGroup();
					}
				)
			},
			// 获取我关注的组
			getFollowGroup(){
				this.$_Request(
					"GET","/api/v2/user/"+uni.getStorageSync('user').data.detail.uid+"/mark/follow/groups",
					{
						"whitelistKeys":"",
						"pageSize":4
					},
					(res) => {
						if(res.data.data.list.length){
							this.listFollowGroup = res.data.data.list;
							this.listFollowGroupState = "success"
						}else{
							this.listFollowGroupState = "empty"
						}
						this.getPostList();
					}
				)
			},
			// 获取关注帖子列表
			getPostList(more){
				if(more == 'more'){uni.showLoading({ title: "加载中" });}
				this.$_Request(
					"GET","/api/v2/user/"+uni.getStorageSync('user').data.detail.uid+"/mark/follow/posts",
					{
						"whitelistKeys":"pid,author.uid,author.avatar,author.nickname,author.nicknameColor,author.roleName,title,content,files,group,hashtags,previewLikeUsers,previewComments,location,createdTimeAgo",
						"page":more == 'more' ? this.listFollowPostPage : "",
					},
					(res) => {
						if(more == 'more'){
							if(res.data.data.list.length){
								this.listFollowPost = this.listFollowPost.concat(res.data.data.list);
								this.listFollowPostPage++
								uni.hideLoading();
							}else{
								uni.showToast({
									title: "没有数据啦",
									icon: "none",
									duration: 1000
								});
							}
						}else{
							if(res.data.data.list.length){
								this.listFollowPost = res.data.data.list;
								this.listFollowPostState = "success"
							}else{
								this.listFollowPostState = "empty"
							}
						}
					}
				)
			},
		},
	}
</script>

<style lang="scss" scoped>
.public-list-follow{
	.split-title{
		display: flex;
		align-items: center;
		padding: 15rpx 25rpx;
		border-bottom: 1rpx solid $BeiJingSe;
		border-top: 25rpx solid $BeiJingSe;
		margin-top: 15rpx;
		view{
			width: 10rpx;
			height: 28rpx;
			border-radius: 5rpx;
			background: $LanSe;
			margin-right: 10rpx;
		}
	}
	.list-follow{
		display: flex;
		flex-wrap: wrap;
		.for{
			width: 120rpx;
			margin: 25rpx 0 0 25rpx;
			.avatar{
				width: 120rpx;
				height: 120rpx;
				overflow: hidden;
				position: relative;
				.image{
					width: 120rpx;
					height: 120rpx;
					overflow: hidden;
					border-radius: 100%;
					position: absolute;
					top: 0;
					left: 0;
					z-index: 1;
					background: $BeiJingSe;
					.icon-wodeguanzhu{
						width: 120rpx;
						height: 120rpx;
						overflow: hidden;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size:50rpx;
						line-height:50rpx;
					}
				}
				.roleName{
					width: 100rpx;
					height: 30rpx;
					background: $ZhanWeiSe;
					position: absolute;
					bottom: 0;
					left: 10rpx;
					z-index: 2;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 18rpx;
					line-height: 18rpx;
					border: 1rpx solid #FFF;
					border-radius: 5rpx;
					text{
						display: -webkit-box;
						/*!autoprefixer:off*/
						-webkit-box-orient: vertical;
						/*autoprefixer:on*/
						-webkit-line-clamp: 1;
						overflow: hidden;
						color: #FFF;
					}
				}
			}
			.icon-wodeguanzhu{
				width: 120rpx;
				height: 120rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background: $BeiJingSe;
				color: $YuanSe;
				border-radius: 100%;
			}
			.nickname{
				text-align: center;
				text{
					font-size: 28rpx;
					display: -webkit-box;
					/*!autoprefixer:off*/
					-webkit-box-orient: vertical;
					/*autoprefixer:on*/
					-webkit-line-clamp: 1;
					overflow: hidden;
				}
			}
		}
		
	}
	.list-follow-group{
		.for{
			display: flex;
			align-items: center;
			margin: 15rpx 25rpx 0 25rpx;
			border-bottom: 1rpx dashed $BeiJingSe;
			padding-bottom: 15rpx;
			.cover{
				flex-shrink: 0;
				width: 60rpx;
				height: 60rpx;
				overflow: hidden;
				border-radius: 100%;
				margin-right: 15rpx;
			}
			.gname{
				flex: 1;
				margin: 0 15rpx 0 0;
			}
			.follow-button{
				flex-shrink: 0;
			}
		}
	}
	.list-interact{
		padding: 0 25rpx;
		.for{
			padding: 25rpx 0;
			border-bottom: 1rpx solid $BeiJingSe;
			.left{
				width: 80rpx;
				height: 80rpx;
				overflow: hidden;
				border-radius: 15rpx;
			}
			.right{
				flex: 1;
				margin-left: 25rpx;
				.nickname{
					font-weight: bold;
					.P{
						font-weight: normal;
						padding-left: 15rpx;
					}
				}
				.title{
					font-weight: bold;
					margin-top: 5rpx;
					display: -webkit-box;
					/*!autoprefixer:off*/
					-webkit-box-orient: vertical;
					/*autoprefixer:on*/
					-webkit-line-clamp: 1;
					overflow: hidden;
				}
				.content{
					word-break: break-all;
					margin-top: 5rpx;
					display: -webkit-box;
					/*!autoprefixer:off*/
					-webkit-box-orient: vertical;
					/*autoprefixer:on*/
					-webkit-line-clamp: 3;
					overflow: hidden;
				}
				.image{
					flex-wrap: wrap;
					margin-top: 10rpx;
					view{
						width: 194rpx;
						height: 150rpx;
						overflow: hidden;
						box-shadow: 0 0 1rpx $ZhanWeiSe;
						margin-top: 10rpx;
					}
					view:nth-child(2),view:nth-child(5),view:nth-child(8){
						margin: 10rpx 10rpx 0 10rpx;
					}
					// #ifdef MP-WEIXIN
					view{
						margin-top: 8rpx;
					}
					view:nth-child(2),view:nth-child(5),view:nth-child(8){
						margin: 8rpx 8rpx 0 8rpx;
					}
					// #endif
				}
				.video{
					margin-top: 20rpx;
					width: 100%;
					height: 300rpx;
					overflow: hidden;
					border-radius: 10rpx;
					position: relative;
					.image-cover{
						position: absolute;
						top: 0;
						left: 0;
						z-index: 1;
						width: 100%;
						height: 300rpx;
						overflow: hidden;
					}
					.icon-play{
						position: absolute;
						top: 0;
						left: 0;
						z-index: 2;
						width: 100%;
						height: 300rpx;
						align-items: center;
						justify-content: center;
						color: #FFF;
						text-shadow: 0 0 1rpx #000;
						font-size: 100rpx;
						line-height: 100rpx;
						background-color:rgba(0,0,0,0.5);
					}
				}
				.group{
					display: flex;
					align-items: center;
					margin-top: 25rpx;
					._group{
						display: flex;
						align-items: center;
						background: $BeiJingSe;
						border-radius: 100rpx;
						margin-right: 20rpx;
						view{
							width: 45rpx;
							height: 45rpx;
							overflow: hidden;
							border-radius: 100%;
						}
						text{
							font-size: 22rpx;
							line-height: 22rpx;
							padding: 0 20rpx 0 15rpx;
						}
					}
					._hashtag{
						display: flex;
						align-items: center;
						border-radius: 100rpx;
						height: 45rpx;
						background: $BeiJingSe;
						font-size: 22rpx;
						line-height: 22rpx;
						padding: 0 15rpx;
						margin-right: 20rpx;
					}
				}
				.post-info{
					margin: 25rpx 0;
					align-items: center;
					._position{
						display: flex;
						align-items: center;
						line-height: 22rpx;
						margin-right: 10rpx;
						text{
							font-size: 22rpx;
							line-height: 22rpx;
							color: $ZhanWeiSe;
						}
						.iconfont{
							margin-right: 5rpx;
						}
						._position_POI{
							max-width: 350rpx;
							display: -webkit-box;
							/*!autoprefixer:off*/
							-webkit-box-orient: vertical;
							/*autoprefixer:on*/
							-webkit-line-clamp: 1;
							overflow: hidden;
						}
					}
					.type{
						flex: 1;
						align-items: center;
						justify-content: flex-end;
						text{
							margin-left: 10rpx;
							color: #FFF;
							font-size: 18rpx;
							line-height: 18rpx;
							padding: 5rpx;
							border-radius: 2rpx;
						}
						.icon-gengduo{
							display: flex;
							align-items: center;
							justify-content: center;
							color: $YuanSe;
							padding: 0 10rpx;
							height: 26rpx;
						}
					}
				}
				.like{
					padding: 15rpx 20rpx;
					line-height: 38rpx;
					border-bottom: 1px solid $BianKuangSe;
					text{
						color: $ShenLanSe;
					}
					.icon-dianzan{
						font-size: 32rpx;
						padding: 0 5rpx 0 0;
						position: relative;
						top: .5rpx;
					}
					.H3{
						line-height: 38rpx;
						margin-right: 10rpx;
					}
				}
				.comment{
					padding: 10rpx 0 15rpx 0;
					border-radius: 10rpx;
					._for{
						padding: 5rpx 25rpx 0 25rpx;
						line-height: 40rpx;
						text{
							font-size: 28rpx;
						}
						._nickname{
							flex-shrink: 0;
							padding-right: 10rpx;
						}
						.icon-yuyin{
							font-size: 22rpx;
							line-height: 22rpx;
							padding-right: 5rpx;
							color: $LvSe;
						}
					}
				}
			}
		}
		.more{
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28rpx;
			line-height: 28rpx;
			color: $ZhanWeiSe;
			padding: 35rpx 0;
		}
	}
}
</style>